package ee.ut.cs.mc.madp.p2pdivider.fragment;

import android.app.Fragment;
/**
 * Enumeration of fragments used in layout
 * 
 * @author Kaarel Jõgeva
 */
public enum UIFragment {
    DEVICES(DevicesFragment.class),
    MEDIA(MediaFragment.class),
    PLAY(PlayFragment.class);

    private final Class<?> clazz;

    private UIFragment(Class<?> clazz) {
        this.clazz = clazz;
    }

    public static UIFragment getFragment(int ordinal) {
        for (UIFragment f : values()) {
            if (f.ordinal() == ordinal) {
                return f;
            }
        }

        throw new RuntimeException("No UIFragment found for ordinal " + ordinal);
    }

    public static UIFragment getFragment(Class<?> clazz) {
        for (UIFragment f : values()) {
            if (clazz.equals(f.getClazz())) {
                return f;
            }
        }

        throw new RuntimeException("No UIFragment found for class " + clazz);
    }

    @SuppressWarnings("unchecked")
    public Class<? extends Fragment> getClazz() {
        return (Class<? extends Fragment>) clazz;
    }

}
